package com.sky.business.sys.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * MQTT信息表
 */
@Data
@NoArgsConstructor
@TableName(value = "d_mqtt_message", autoResultMap = true)
public class MQTTMessage implements Serializable {

    public enum Type{
        REPORT,
        DISPATCHER
    }

    @Serial
    private static final long serialVersionUID = 2741317465645296309L;

    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "ID")
    private Long id;

    @TableField(value = "type")
    @Schema(description = "类型")
    private Type type;

    @TableField(value = "event")
    @Schema(description = "事件")
    private String event;

    @TableField(value = "device_id")
    @Schema(description = "设备ID")
    private String deviceId;

    @TableField(value = "task_id")
    @Schema(description = "任务ID")
    private String taskId;

    @TableField(value = "node_id")
    @Schema(description = "节点ID")
    private Integer nodeId;

    @TableField(value = "message")
    @Schema(description = "消息内容")
    private String message;

    @TableField(value = "create_date")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "创建时间")
    private Date createDate = new Date();

    public MQTTMessage(Type type, String message) {
        this.type = type;
        this.message = message;
    }

}
